#include<stdlib.h>
#include<stdio.h>

// 结点类
struct ListNode {
    int val;
    struct ListNode *next;
};

// 需要实现的函数
void deleteDuplicates(struct ListNode *head);


// 去重函数实现
int binary_find(int *arr,const int len,const int target)
{
    int left = 0;
    int right = len-1;

    while (left <= right)
    {
        int mid = left+(right-left)/2;

        if (arr[mid] < target)
        {
            left = mid+1;
        }
        else if (arr[mid] > target)
        {
            right = mid-1;
        }
        else 
        {
            return mid;
        }
    }
    return -1;
}

void deleteDuplicates(struct ListNode*head)
{
    // 判空
    if (!head)
    {
        return;
    }
    if (!head->next)
    {
        return ;
    }

    // 不用哑节点
    // 这次需要手写半个vector容器
    int len = 1;
    int vector[100000];
    vector[0] = head->val;
    int i = 1;

    // 遍历并记录
    struct ListNode*temp = head->next;
    struct ListNode*prev = head;

    while (temp)
    {
        if (binary_find(vector,len,temp->val) == -1)
        {
            vector[i] = temp->val;
            len++;
            i++;
            prev = prev->next;
            temp = temp->next;
        }
        else 
        {
            struct ListNode* to_delete = temp;
            prev->next = temp->next;
            temp = temp->next;

            // 安全释放或者不释放
            free(to_delete);
            to_delete = NULL;
        }
    }

}

int main() {
    int amount;
    struct ListNode *head, *temp;
  
    // 读入数据
    scanf("%d", &amount);
    for (int i = 0; i < amount; i++) {
        struct ListNode *input = (struct ListNode *) malloc(sizeof(struct ListNode));
        scanf("%d", &(input->val));

        if (i == 0) {
            head = input;
            temp = head;
        } else {
            temp->next = input;
            temp = temp->next;
        }

        if (i == amount - 1)
            temp->next = NULL;
    }
  
    // 执行函数
    deleteDuplicates(head);

    // 输出 ,这里把 head 改了？？？
    while (head != NULL) {
        printf("%d ", head->val);
        head = head->next;
    }
}

// TODO: 在下方补全函数实现